﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using LiveNet.Authentication;
using LiveNet.Contacts;

public partial class Contacts : System.Web.UI.Page
{
    LiveContacts lc;
    protected void Page_Load(object sender, EventArgs e)
    {
        string email = "scottisafool@gmail.com";
        string lid = "fabdddc5cad93494";
        string token = @"EwCwARAnAAAUaiat%2Fx8TEXYT53ezUhJ8EEISAEWAAPn1LajzTPb48JC%2FGaTgug2qKbKeJNAxVI0%2BnTPHAPyjK6sM00CFVzajIX0fZ0IhYurTGnhO4ztYm9pJqUM07D0uZd%2BlsY28gnGhS5G4qjZnJOkW1hQVfAwrnoT%2BpgV48zaNUcSH%2Bb8GXjIWAS8mvkKJyUTUrUshcKKqooN6CuAsA2YAAAi%2BCt%2FtlSCBsQABUXmKM7Go65OsgM9cL6PnZaKMMyX1ZtJRVrr%2B920h3pWWpeICLEnXqCLTDqjFO9j6sLqkv7P3MpbtNbJaH9pI4iVozhEmxOzzDIhZCWNDoCb0tJyansNjUcyMMSGKD8%2FRZsHr%2FTlY4%2BRFD%2FcV10Dnsk4Pf2O7oaayH8wlWRcOLq0ZyrVY5Qwz%2B8WET%2BnorNVM8BockbY3oM8LlVWVEZXOjlPCZkIohbe1C%2BhBDmMxvE%2B5JfEIVIH8WgxYzD0KyU9SGOnzN5Nritz9UYrdydPqCCNbXoa5%2FxwHMMQwg5lfsNCeTt6tH3xKD4lxXgg0lC9lLpXty4XhL%2FV8il8B1g4eKQAA";
        //string token = "eact%3DkK5tF0wSUcCm%252F0A6wBur%252BqLGLdq5RbPEHLXPbLrkQnnY4OaOEv1wBGpwtivsXJpzYspOq1hO17sGlnkI84Pq5%252BxTMv4H15Y5zPAX%252BcTVDNf7tXqHoyCqHzQ4WAlIo6rqK96tZ8PYaF4Ad0H0jedsHFMlGjwrHj%252F9jf6w72Q2suCozsw0L83fDhyVlsXYS%252BhZVoM1p6iOJwTk4lMZj5%252BgB6nV3xlJxdfTohsSkITKo2nGlwHs9xefaJCVzHPrYNV2GCJkUFzjO2FlY7WWdR3r3l7e%252B3H3X%252F3d3BK2Q0wQeKSiae3iq0FIQwxqXz6eoX24hwWyRFw9dXMIwJzizIvIrYqI83dL9MMwgzm93IaMLK3qJ3bqtlYr%252FVSn3vAn1S4yb9qR%252BeeUSX%252BrNQl2MszOr3jOFJzIKRF2Xlnep7LZNCQRagBHV%252BdGJKWZ9FSneasLLo7vAJWU8CuZb0Fru03FJNBuU%252Fq3VBKAw2JfREobL%252FWb3hpJ13oz%252F2eKm5ifwSQHtyGK878x2vKktNJlNawv48liHqMGeaJ%252FTQ%252FAKquzxDgA97Bk7WsWXaM5ez%252BxJ%252BpSCR2Dd4qBHR%252BYJJ5plwA%252B%252F4%252FQmMpnWs6uD0oKWKQcG99xJfYMqIuUoOUqAufwVXw1tj3W3bcL8WpmiK0yZCVac%252BZtcMwD0eK7kV2QtgKn3yfhTt28%252F9mxINrCEDRqM2EBjLQ7vLMN5ZzCTsrSEBveOepg%252BnGYAM7Owb7p4hY0Mp40K3thItvEJrTQM3CieohTXbeanpOZEa0YHdd%252Fus6e5B3mHrRuCYE4Z1mSVdJYAm5s71dZBjhiqz6PAvMAq25S2k6kcTebu89AlD7u7aUoCLHE3Yt5yr90r5y6%252BgpT4F2fzp%252FAYfZ1xtWdGxx9SO7ngpFwSROvmWNf%252BT2FVPwVX41iT6F9Wy2jYQRnVHTGGuLwHXvvsMJt4NyOIvxt%252BGUGiQHd0JZaULAyMUhLRmZUPHZao80OG6iC8jkcm%252BKpb0t6EBaEQsJMWD2tODlmGo0hYdTY15aPWe2cVjfzCXd6uu%252BeKx00QfUfTCFzYZxEMAvhCaWDiMc2wsdCmR0hba0w5Lly1GFvBmB96AKdn9O0aXOsoFUuS6cAQag%252BjtVxDAw7knvPz%252BC6sGpBIJe0jsZL4UEfz2UNUps77fSQUlKEr4PaltD7Brh0wqHTqGlH9%252B4of7fs%252BugAVyPuvkAfhtddj19gEqZs%252Fx8RKQ4hGYvbvMC4YUpQvKZp8bFHxRpYH8WOmBHwzR0UqI1C4l0zCGtOxLh9MPlR5a%252BNEkClkIrhNXOJu43N%252B9RmVjkKeGYGeJ%252BCSAtB0E4NRldWeOQoE5AcvDOKrPANV6se3ckiTxPN6v3zGPhaW%252BRhwThlnBNG7eJW%252FEeRll12HoqJ6UJtNmwK";
        lc = new LiveContacts(lid, token, AuthenticationToken.DelegatedToken);
        //lc = new LiveContacts(email, token, AuthenticationToken.DomainAuthenticationToken);
        
    }
    protected void btnGetContacts_Click(object sender, EventArgs e)
    {
        lc.GetContacts();
        ContactCollection contacts = lc.Contacts;
        List<string> emails = new List<string>();

        foreach (Contact c in contacts)
        {
            
            foreach (Email em in c.Emails)
            {
                emails.Add(em.Address);
            }
        }

        GridView1.DataSource = emails;
        GridView1.DataBind();
    }
}
